import cv2
import numpy as np
import torch
# import cv2
from PIL import Image
from matplotlib import pyplot as plt
from torchvision import transforms

img = Image.open(r'D:\lx\ysty.JPEG')
# img.show()
transform1 = transforms.Compose([
    transforms.ToTensor(),
    transforms.Normalize([0.485, 0.465, 0.006], [0.225, 0.024, 0.225])

])

timg = transform1(img)
print(img.size)
a = img.size
# print(timg.size())
# a = timg.permute(1, 2, 0)
# plt.imshow(a)
# plt.show()
img = cv2.imread('ysty.JPEG')
stride=32
target_size = 640
w = a[0]
h = a[1]
size_base = max(w, h)
size_rate = size_base / target_size
w_n = int(w / size_rate)
h_n = int(h / size_rate)
n_imge = img.resize((w_n, h_n))
print(img.size)
pad = int(round((stride - np.mod(min(n_imge.size),stride))/2-0.1))
padimge = cv2.copyMakeBorder(img,0,0,pad,pad,cv2.BORDER_CONSTANT,value=(114,114,114))
plt.imshow(padimge)